#include<iostream>
#include<fstream>
#include<queue>
using namespace std;
 
struct node {
	int x,y;
	int tcnt;
 
	node(void) {}
	node(int xx, int yy, int tt): x(xx), y(yy), tcnt(tt){}
};
 
int m,t;
char mat[12][12] = {};
 
int bfs(int x0, int y0, int x1, int y1)
{
	if (x0==x1 && y0==y1)
	{
		return 0; // 若入口就是出口，返回0
	}
	node nd(x0, y0, 0);
	int x,y;
	queue<node> q;
	q.push(nd);
	while (!q.empty())
	{
		nd = q.front();
		q.pop();
		x = nd.x;
		y = nd.y;
		if (x<m-1)
		{
			// 向右走
			if (mat[x+1][y]=='E')
			{
				return nd.tcnt+1; // 找到出口
			}
			else if (mat[x+1][y]=='.')
			{
				q.push(node(x+1,y,nd.tcnt+1));
				mat[x+1][y] = '*';
			}
		}
		if (x>0)
		{
			// 向左走
			if (mat[x-1][y]=='E')
			{
				return nd.tcnt+1;
			}
			else if (mat[x-1][y]=='.')
			{
				q.push(node(x-1,y,nd.tcnt+1));
				mat[x-1][y] = '*';
			}
		}
		if (y<m-1)
		{
			// 向下走
			if (mat[x][y+1]=='E')
			{
				return nd.tcnt+1;
			}
			else if (mat[x][y+1]=='.')
			{
				q.push(node(x,y+1,nd.tcnt+1));
				mat[x][y+1] = '*';
			}
		}
		if (y>0)
		{
			// 向上走
			if (mat[x][y-1]=='E')
			{
				return nd.tcnt+1;
			}
			else if (mat[x][y-1]=='.')
			{
				q.push(node(x,y-1,nd.tcnt+1));
				mat[x][y-1] = '*';
			}
		}
	}
	return -1;
}
 
 
int main()
{
#ifndef ONLINE_JUDGE
	ifstream fin ("G.txt");
	int k,i,j,x0,y0,x1,y1,ans;
	fin >> k;
	while (k--)
	{
		fin >> m >> t;
		for (i=0; i<m; i++)
		{
			for (j=0; j<m; j++)
			{
				fin >> mat[i][j];
				if (mat[i][j]=='S')
				{
					x0 = i;
					y0 = j; // 记录入口
				}
				else if (mat[i][j]=='E')
				{
					x1 = i;
					y1 = j; // 记录出口
				}
			}
		}
		ans = bfs(x0,y0,x1,y1);
		if (ans <= t && ans >= 0)
		{
			cout << "YES" << endl;
		}
		else
		{
			cout << "NO" << endl;
		}
	}
	fin.close();
#endif
#ifdef ONLINE_JUDGE
	int k,i,j,x0,y0,x1,y1,ans;
	cin >> k;
	while (k--)
	{
		cin >> m >> t;
		for (i=0; i<m; i++)
		{
			for (j=0; j<m; j++)
			{
				cin >> mat[i][j];
				if (mat[i][j]=='S')
				{
					x0 = i;
					y0 = j;
				}
				else if (mat[i][j]=='E')
				{
					x1 = i;
					y1 = j;
				}
			}
		}
		ans = bfs(x0,y0,x1,y1);
		if (ans <= t && ans >= 0)
		{
			cout << "YES" << endl;
		}
		else
		{
			cout << "NO" << endl;
		}
	}
#endif
}